// import Account from "./account";
import Base from "./base";
import { v4 as uuidv4 } from 'uuid'
class Component extends Base {
  property: string = 'C';
  children: any = undefined;
  componentName = 'Component';
  supplement = {};
  tx_component: string = '';
  // 默认无数据，当提交的时候会被分配 见 helper export { cloneMarketComponentAndInjectAccount }
  account: undefined;
  // 组件列表 默认无数据 当提交的时候会被分配 见 helper
  components: any = {};

  ckey = Date.now();
  type: string = '';
  // 开启/关闭
  switch: boolean = false;
  // 严格与组件的params相关 这里面的数据会直接提交给后端，需要保证value的对应
  value: Record<string, any> = {
    // link_name_text: '',
    // link_name_type: ''
  }
  // 组件附加值
  info: Record<string, any> = {
    // link_name_text: '',
    // link_name_type: ''
  }
  media_restriction = {};
  // skip: 'PAGE_TYPE_WECHAT_MINI_PROGRAM' | 'PAGE_TYPE_WECHAT_CANVAS' = 'PAGE_TYPE_WECHAT_MINI_PROGRAM'
  textUrl = ''
  hasFloatCard = false
  hasCountDown = false
  barrage = ''

  isDataExplicit = false
  isSaveWxChannel = false
  name = ''

  description: string = ''
  restriction: any = {}
  optional: any = []
  "element_type": string = '';
  "field_type": string = '';
  required: boolean = true

  constructor(options: any) {
    super();
    // 默认行为
    const defaultChildren = this.children;
    options.children = Object.assign(defaultChildren || {}, options.children || {});
    this.init(options);
    return this;
  }
  // 提交的组件参数 默认取 value的值
  query(options?:any): any {
    return this.value;
  }

  reset() {
    this.uuid = uuidv4();
  }

  update(options:any) {
    this.init(options);
  }
}

export default Component
